// 防止处理多次点击
function noMultipleClicks(methods, ...info) {
	// methods是点击后需要执行的函数， info是函数需要传的参数
	let that = this;
	if (that.noClick) {
		// 第一次点击
		that.noClick = false;
		if ((info && info !== '') || info == 0) {
			// info是执行函数需要传的参数
			methods(...info);
		} else {
			methods();
		}
		setTimeout(() => {
			that.noClick = true;
		}, 4000)
	} 
}
function setCodeTimer() {
  console.log(this)
  if (this.time == 0) {
    sessionStorage.setItem(`${this.$route.name}Timestamp`, Date.now());
    this.time = 60;
  }

  let timer = setInterval(() => {
    this.time -= 1;
    if (this.time <= 0) {
      clearInterval(timer);
    }
  }, 1000);
}
function getCodeTimer() {
  let timestamp = sessionStorage.getItem(this.$route.name + "Timestamp");
  if (Date.now() - timestamp < 60 * 1000) {
    this.time = 60 - parseInt((Date.now() - timestamp) / 1000);
    this.$setCodeTimer();
  }
}

//导出
export {
	noMultipleClicks, // 禁止多次点击
  setCodeTimer,
  getCodeTimer
}


